from time import sleep

from selenium.webdriver.common.by import By

from pages.bases.bases import BasesPage
from pages.page.indexpage import IndexPage
from pages.utils import GetDriver


class ApprovalPage(BasesPage):
    def __init__(self):
        super().__init__("web")
        # 待处理
        self.pending = (By.XPATH, '//*[@id="app"]/div/div[2]/div/div[1]/div[1]/div/div/a[1]/div/div[2]')
        # 点击查询项
        self.gettype = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[3]/div/div[1]/form/div[1]/div/div/'
                                  'div[1]/div[1]/span[2]')
        # 点击查询类别
        self.getclass = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[3]/div/div[1]/form/div[1]/div/div/'
                                   'div[1]/div[2]/ul[2]/li')
        # 输入数据
        self.getdate = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[3]/div/div[1]/form/div[1]/div/div/div[2]/input')
        # 点击查询
        self.getbutton = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[3]/div/div[1]/form/div[2]/div/button[1]')
        # 进入工单
        self.gowork = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[3]/div/div[2]/div[2]/div[2]/div/div/'
                                 'div[2]/table/tbody/tr/td[1]')
        # 接单
        self.button = (By.XPATH, '//*[@id="app"]/div/div[3]/div/div[1]/div[5]/div/div[1]/button[1]')
        # 输入完成说明
        self.inputexplain = (By.XPATH, '/html/body/div[47]/div[2]/div/div/div[2]/div/form/div/div[1]/div/'
                                       'div[1]/textarea')
        self.succbutton = (By.XPATH, '/html/body/div[47]/div[2]/div/div/div[3]/div/div/button[1]')


    def execute_work(self, lable):
        '''
        :param lable: 输入之前工单的标题
        '''
        self.click(self.pending)
        self.click(self.gettype)
        self.select_type(self.getclass, "标题")
        self.input_text(self.getdate, lable)
        self.click(self.getbutton)
        self.click(self.gowork)
        try:
            self.click(self.button)
            self.click(self.button)
        finally:
            self.input_text(self.inputexplain, "随便说说")
            self.click(self.succbutton)



